package com.esoon.controller;

import com.esoon.entity.MyPhoneArea;
import com.esoon.service.ThirdpartyPhoneAreaService;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

/**
 * @ClassName ThirdpartyPhoneAreaController 来电归属地管理
 * @Description TODO    来电归属地查询，在csr系统中有一张表 维护着电话号码与地区的关系。
 * @Author 2020/9/23 13:58
 * @Version 1.0
 **/
@Api(value = "来电归属地管理")
@RestController
@RequestMapping(value = "/v1/ThirdpartyPhoneArea")
public class ThirdpartyPhoneAreaController {
    private static final Logger logger;
    static {
        logger = LoggerFactory.getLogger(ThirdpartyPhoneAreaController.class);
    }
    @Resource
    private ThirdpartyPhoneAreaService thirdpartyPhoneAreaService;
/*
 * @Author Jack
 * @Description //TODO 根据电话号码查询来电归属地，当电话号码来电归属地为新疆时返回 1 不属于新疆时 返回 2 号码长度不为11位时 返回 3
 * @Date 11:47 2020/9/26
 * @Param 
 * @return 
 **/
    @RequestMapping(value = "/selectByPhoneNumber",method = RequestMethod.GET)
    public String selectByPhoneNumber(@RequestParam String phone,@RequestParam String tenantCode){
        logger.info("invoking select XinJiang phone calls attribution interface , the url = '/v1/ThirdpartyPhoneArea/selectByPhoneNumber', the requestParam : phone = [{}] , tenantCode = [{}] ",phone , tenantCode);
        return thirdpartyPhoneAreaService.selectByPhoneNumber(phone,tenantCode);
    }
//根据电话号码查询来电归属地 获取 省 + 市
    @RequestMapping(value = "/selectArea", method = RequestMethod.GET)
    public String selectArea(@RequestParam String phone,@RequestParam String tenantCode){
        try {
            logger.info("invoking select  phone calls attribution interface , the url = '/v1/ThirdpartyPhoneArea/selectArea', the requestParam : phone = [{}] , tenantCode = [{}] ",phone , tenantCode);
            MyPhoneArea myPhoneArea = thirdpartyPhoneAreaService.selectArea(phone,tenantCode);
            if (!ObjectUtils.isEmpty(myPhoneArea)){
                return myPhoneArea.getProvince() + myPhoneArea.getCity();
            }else{
                logger.info("invoking select phone calls attribution interface success! the message is null");
                return "未知区域";
            }
        }catch (Exception e){
            logger.error("the program error, error message = [{}]" , e.toString());
            return "未知地区";
        }
    }
}
